package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.goods.entity.PtGoods;
import com.ibiaoke.goods.service.PtGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 拼团商品Controller
 */
@Controller
public class WxPtGoodsController extends BaseController{


    @Autowired
    private PtGoodService ptGoodService;

    /**
     * 拼团商品列表
     * @return
     */
    @RequestMapping("/listPtGoods")
    @ResponseBody
    public Res listPtGoods(Page page) {
        Customer customer = null;
        Object loginUser = getSession().getAttribute(CommonConsts.LOGIN_SESSION_NAME);
        if(loginUser != null){
            customer = (Customer)loginUser;
        }
        List<PtGoods> ptGoodsList = ptGoodService.listPtGoods(page,customer);
        return Res.create().addResponse("ptGoodsList",ptGoodsList).addResponse("page", page);
    }

    /**
     * 查看拼团商品详情
     * @param PtGoodsId
     * @return
     */
    @RequestMapping("/getPtGoodsById")
    @ResponseBody
    public Res getPtGoods(Integer PtGoodsId){
        PtGoods ptGoods = ptGoodService.getGoodsById(PtGoodsId);
        return Res.create().addResponse("ptGoods",ptGoods);
    }
}
